-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Move storybook.requires.js and Storybook.tsx files from the root directory to the .storybook folder #252
feat: Move storybook.requires.js and Storybook.tsx files from the root directory to the .storybook folder #252
Conversation
…k.tsx files from the root directory to the .storybook folder.
Are you able to test this with expo? I had some issues with the .storybook folder in expo because of the "." it seemed like metro didn't want to find hidden files. |
Good observation! Tested this now with Expo. It seems to work on my machine, but for some reason requires running
As mentioned in the PR description, this could be related to pointing to the local NPM packages, but I'm not sure. Here are the steps that I did to experiment with this branch on Expo (replace git checkout feat/move-files-to-storybook-dir
yarn prepareAll
cd ..
npm install --global expo-cli
expo init -t expo-template-blank-typescript expotest
cd expotest
yarn add /Users/lauriharpf/Repos/lauriharpf/react-native-storybook/app/react-native \
@react-native-async-storage/async-storage \
/Users/lauriharpf/Repos/lauriharpf/react-native-storybook/addons/ondevice-actions \
/Users/lauriharpf/Repos/lauriharpf/react-native-storybook/addons/ondevice-controls \
/Users/lauriharpf/Repos/lauriharpf/react-native-storybook/addons/ondevice-backgrounds \
/Users/lauriharpf/Repos/lauriharpf/react-native-storybook/addons/ondevice-notes \
@storybook/addon-actions \
@react-native-community/datetimepicker \
@react-native-community/slider \
@storybook/addon-controls
yarn
echo "const { getDefaultConfig } = require('expo/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.resolverMainFields = [
'sbmodern',
...defaultConfig.resolver.resolverMainFields,
];
defaultConfig.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
});
module.exports = defaultConfig;
" > metro.config.js;
mkdir .storybook
mkdir components
echo "module.exports = {
stories: [
'./components/**/*.stories.?(ts|tsx|js|jsx)'
],
addons: [
'@storybook/addon-ondevice-notes',
'@storybook/addon-ondevice-controls',
'@storybook/addon-ondevice-backgrounds',
'@storybook/addon-ondevice-actions',
],
};" > .storybook/main.js
echo "import {withBackgrounds} from '@storybook/addon-ondevice-backgrounds';
export const decorators = [withBackgrounds];
export const parameters = {
backgrounds: [
{name: 'plain', value: 'white', default: true},
{name: 'warm', value: 'hotpink'},
{name: 'cool', value: 'deepskyblue'},
],
};" > .storybook/preview.js
echo "import AsyncStorage from '@react-native-async-storage/async-storage';
import { getStorybookUI } from '@storybook/react-native';
import './storybook.requires';
const StorybookUIRoot = getStorybookUI({
asyncStorage: AsyncStorage,
});
export default StorybookUIRoot;" >.storybook/Storybook.tsx
echo "import StorybookUIRoot from './.storybook/Storybook';
export { StorybookUIRoot as default };" > App.tsx
node -e 'const fs = require("fs");
const packageJSON = require("./package.json");
packageJSON.scripts = {
...packageJSON.scripts,
prestart: "sbn-get-stories",
"storybook-watcher": "sbn-watcher"
};
fs.writeFile("./package.json", JSON.stringify(packageJSON, null, 2), function writeJSON(err) {
if (err) return console.log(err);
console.log(JSON.stringify(packageJSON));
console.log("writing to " + "./package.json");
});';
mkdir components/Button;
echo "import React from 'react';
import {TouchableOpacity, Text, StyleSheet} from 'react-native';
interface MyButtonProps {
onPress: () => void;
text: string;
}
export const MyButton = ({onPress, text}: MyButtonProps) => {
return (
<TouchableOpacity style={styles.container} onPress={onPress}>
<Text style={styles.text}>{text}</Text>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
container: {
paddingHorizontal: 16,
paddingVertical: 8,
backgroundColor: 'violet',
},
text: {color: 'black'},
});
" > components/Button/Button.tsx;
echo "import React from 'react';
import {ComponentStory, ComponentMeta} from '@storybook/react-native';
import {MyButton} from './Button';
const MyButtonMeta: ComponentMeta<typeof MyButton> = {
title: 'MyButton',
component: MyButton,
argTypes: {
onPress: {action: 'pressed the button'},
},
args: {
text: 'Hello world',
},
};
export default MyButtonMeta;
type MyButtonStory = ComponentStory<typeof MyButton>;
export const Basic: MyButtonStory = args => <MyButton {...args} />;
" > components/Button/Button.stories.tsx
yarn sbn-get-stories Now |
@lauriharpf that's a really strange behaviour 🤔. If the .storybook folder is renamed without the "." does it work more consistently? |
Yeah, it's puzzling to me as well. Good suggestion, haven't tested that yet - will try to find time for it e.g. tomorrow. Could also double-check how the |
Was now able to test this in more detail:
All of the experiments where I had local dependencies, or in other words did this
caused
unless I ran Since the behaviour was the same for commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at this again now and it seems fine to me, I think the best course of action would be to merge and then test it in the next alpha. That way we can be sure the issues aren't some edge case of using local dependencies.
Sorry for the delay, taken me a bit to get back into the swing of things after my holiday 😅 .
…t directory to the .storybook folder. (storybookjs#252) Closes storybookjs#238
Issue: #238
What I did
Changed the
loader.js
script (that generatesstorybook.requires.js
), the V6 alpha instructions and the example project so that bothstorybook.requires.js
andStorybook.tsx
are moved to the.storybook
directory from the root.How to test
/examples/native
directory. Confirm that the stories still work both on iOS and Android.yarn prepareAll
in the root of the project. Then follow the v6 alpha setup guide inv6README.md
, but in the same way as in fix: Fix #120 (running "yarn web" on Expo fails). #251 , use the local Storybook React Native dependencies instead of the ones pulled from NPM.Note: In step 2,
cd ios; pod install; cd ..;
fails on my box with the following error:Running
yarn
in the root ofRnSBSixAlpha
fixes it. I'm unsure why this happens, but I suspect that it might be caused by using the local React Native Storybook dependencies. The same thing happens with thenext-6.0
branch, so it shouldn't be related to this change.